﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.ProfessionalTeam.DAL;

public partial class MapInfo_ProfessionalTeam_ProfessionalProc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //返回上一页
            if (Request.UrlReferrer != null)
            {
                ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
            }
            init();
        }
    }
    //返回上一页
    protected void lbtReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect(ViewState["UrlReferrer"].ToString());
    }

    void init()
    {
        string DepartmentId = Request["DepartmentId"];
        TeamDataContext tdc = new TeamDataContext();
        List<ProfessionalProc> procs = tdc.ProfessionalProc.Where(o => o.DepartmentId == DepartmentId).ToList<ProfessionalProc>();
        gv.DataSource = procs;
        gv.DataBind();

        lblDepartment.Text = Yipusoft.Account.BLL.Department.GetDepartment(DepartmentId).ShortName;
    }

    protected void gvSoldiers_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }

    protected void gvSoldiers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            ProfessionalProc proc = e.Row.DataItem as ProfessionalProc;
            Label lblName = e.Row.FindControl("lblName") as Label;
            TeamDataContext tdc = new TeamDataContext();
            ProcsType type = tdc.ProcsType.Where(o => o.Id == Convert.ToInt32(proc.ProcessionType)).FirstOrDefault();
            lblName.Text = type.TypeName;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string url = "ProcNew.aspx?DepartmentID=" + Request["DepartmentId"];
        Response.Redirect(url);
    }
    protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            TeamDataContext tdc = new TeamDataContext();
            Guid Id = new Guid(e.CommandArgument.ToString());
            ProfessionalProc proc = tdc.ProfessionalProc.Where(o => o.id == Id).FirstOrDefault();
            tdc.ProfessionalProc.DeleteOnSubmit(proc);
            tdc.SubmitChanges();
            init();
        }
        else if (e.CommandName == "Editcom")
        {
            Response.Redirect(Server.HtmlEncode("ProcNew.aspx?DepartmentId=" + Request["DepartmentId"]) + "" + "&Pid=" + e.CommandArgument + "");
        }
        else if (e.CommandName == "SD")
        {
            Response.Redirect(Server.HtmlEncode("HelpNew.aspx?DepartmentId=" + Request["DepartmentId"]) + "" + "&Pid=" + e.CommandArgument + "&Type=1");
        }
    }
}
